home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 4 / MacMania 4.toast / / Demo's / Igor Demo Pro / 1 PutContentsIn Igor Pro Folder / WaveMetrics Procedures / Graphing / Probability Graph < prev    next >
Text File  |  1996-01-29  |  27KB  |  996 lines

  1. #pragma rtGlobals= 0        // this procedure has NOT been updated to use the new globals method
  2.  
  3. // NOTE: This procedure has not yet been updated to be Igor Pro 3.0 savvy. You
  4. // should not use waves with liberal names or those residing in data folders
  5. // other than root:.
  6.  
  7. #include <Strings as Lists>
  8.  
  9. |****************************************************
  10. Menu "Macros"
  11.     "Draw Probability Graph…", Probability_Axis()
  12. end
  13.  
  14. Function  Probability_Axis()
  15.     Variable/D sq=sqrt(2)
  16.     Make/D/o/N=5000 tmp_qq_erf
  17.     SetScale/I x,0,10,tmp_qq_erf
  18.      tmp_qq_erf=0.5*erf(x/sq)
  19.     
  20.     Variable/D/G    gPAC_Red
  21.     Variable/D/G    gPAC_Green
  22.     Variable/D/G    gPAC_Blue
  23.     Variable/D/G    gPAC_LineWidth
  24.     Variable/D/G    gPAC_LabelGrout
  25.     Variable/D/G    gPAC_TicLength
  26.     Variable/D/G    gPAC_FontFace
  27.     Variable/D/G    gPAC_FontSize
  28.     Variable/D/G    gPAC_Min
  29.     Variable/D/G    gPAC_Max
  30.         
  31.     gPAC_Red=0
  32.     gPAC_Green=0
  33.     gPAC_Blue=0
  34.     gPAC_LineWidth=1
  35.     gPAC_LabelGrout=0.03
  36.     gPAC_TicLength=0.02
  37.     gPAC_FontFace=0
  38.     gPAC_FontSize=10
  39.     gPAC_Min=0.01
  40.     gPAC_Max=0.99
  41.     
  42.     | DoWindow /T  probAxisControl, "Probability Axis Control"
  43.     Execute("probAxisControl()")
  44. end
  45.  
  46. |****************************************************
  47.  
  48. Function/D scalePosition(inx)
  49.     Variable/D    inx
  50.     String/g      wName="tmp_qq_erf"
  51.     Variable    smaller=0
  52.     
  53.     if(numType(inx)!=0)
  54.         return(inx)
  55.     endif
  56.     
  57.     
  58.     if((inx<gPAC_Min) %| (inx>gPAC_Max))        || establish limits
  59.         return(NaN)
  60.     endif
  61.  
  62.     if(inx==0.5)                                    || simple case-no need to calculate
  63.         return(0)
  64.     endif
  65.     
  66.     if(inx<0.5)
  67.         smaller=1
  68.         inx=0.5-inx
  69.     else
  70.         smaller=0
  71.         inx=inx-0.5
  72.     endif
  73.     
  74.     variable/d outx=NaN
  75.     findLevel/q   $wName,inx
  76.     if(V_flag==0)                    || will return a Nan otherwise
  77.         outx=V_LevelX
  78.     endif
  79.     
  80.     if(smaller==0)
  81.         return(outx)
  82.     else
  83.         return(-outx)
  84.     endif
  85. end
  86.  
  87. |****************************************************
  88.  
  89. |****************************************************
  90.  
  91. function drawProbabilityAxis(whichAxis,waveName,fontName,fontSize,fontFace,ticLen,labelGrout)
  92.     Variable whichAxis,fontSize,fontFace,ticLen,labelGrout
  93.     String waveName,fontName
  94.     
  95.     String topGraphWindowName=WinName(0,1)        |   find the top graph window
  96.     DoWindow /F  $topGraphWindowName                |   bring to the front
  97.     SetDrawLayer     progAxes                            |   
  98.  
  99.     SetDrawEnv linethick=gPAC_LineWidth
  100.     SetDrawEnv linefgc=(gPAC_Red,gPAC_Green,gPAC_Blue)
  101.     SetDrawEnv textrgb=(gPAC_Red,gPAC_Green,gPAC_Blue)
  102.     SetDrawEnv save
  103.  
  104.     do
  105.         if(whichAxis==1)
  106.             GetAxis/Q bottom
  107.             if(V_Flag==0)
  108.                 ModifyGraph noLabel(bottom)=2,axThick(bottom)=0
  109.             endif
  110.             drawline 0,1,1,1
  111.             drawTics(1,waveName,fontName,fontSize,fontFace,ticLen,labelGrout)
  112.             break
  113.         endif
  114.         
  115.         if(whichAxis==2)
  116.             GetAxis/Q left
  117.             if(V_Flag==0)
  118.                 ModifyGraph noLabel(left)=2,axThick(left)=0
  119.             endif
  120.             drawline 0,0,0,1
  121.             drawTics(2,waveName,fontName,fontSize,fontFace,ticLen,labelGrout)
  122.             break
  123.         endif
  124.         
  125.         if(whichAxis==3)
  126.             GetAxis/Q right
  127.             if(V_Flag==0)
  128.                 ModifyGraph noLabel(right)=2,axThick(right)=0
  129.             endif
  130.             drawline 1,0,1,1
  131.             drawTics(3,waveName,fontName,fontSize,fontFace,ticLen,labelGrout)
  132.             break
  133.         endif
  134.         
  135.         if(whichAxis==4)
  136.             GetAxis/Q top
  137.             if(V_Flag==0)
  138.                 ModifyGraph noLabel(top)=2,axThick(top)=0            
  139.             endif
  140.             drawline 0,0,1,0
  141.             drawTics(4,waveName,fontName,fontSize,fontFace,ticLen,labelGrout)
  142.             break
  143.         endif
  144.     while(0)
  145. end
  146.  
  147. |****************************************************
  148. Function drawTics(which,waveName,fontName,fontSize,fontFace,ticLen,labelGrout)
  149.     Variable     which,fontSize,fontFace,ticLen,labelGrout
  150.     String         waveName,fontName
  151.     
  152.     Variable     numTics=numpnts($waveName)
  153.     variable     i=0
  154.     String        labelString
  155.     Variable/D     xPos
  156.     Wave/D        w=$waveName
  157.     
  158.     || we are sorting the wave here
  159.     sort w,w                                        
  160.     
  161.     Variable/D    lowVal=scalePosition(gPAC_Min)
  162.     Variable/D    highVal=scalePosition(gPAC_Max)
  163.  
  164.     if((lowVal<-50) %| (highVal<-50))
  165.         Print "Processed wave contains bad values."
  166.         Print lowVal,highVal
  167.         return(0)
  168.     endif
  169.         
  170.     Variable/D    scaleFactor=1.0/(highVal-lowVal)    
  171.     
  172.     Variable/D    offsetx,offsety        
  173.     
  174.     GetWindow $WinName(0,1), psize
  175.     variable plotHeight=V_bottom-V_top
  176.         
  177.     ControlInfo /W=probAxisControl checkPercentLabel
  178.     Variable convert2Percent=V_value
  179.         
  180.     if(which==1)        || bottom Axis
  181.         offsety=ticLen+labelGrout+(fontSize/plotHeight)
  182.         Variable offsetPts=offsety*plotHeight
  183.         if((offsetPts/fontSize)<(1.7*fontSize))
  184.             offsety=(1.7*fontSize)/plotHeight
  185.         endif
  186.         offsety+=0.02                            || for 0.5 extension
  187.         do
  188.             if(numType(w[i])==0)
  189.                 if(convert2Percent==0)
  190.                     labelString=num2str(w[i])
  191.                 else
  192.                     labelString=num2str(100*w[i])
  193.                 endif
  194.                 
  195.                 xPos=(scalePosition(w[i])-lowVal)*scaleFactor
  196.                 if(w[i]==0.5)
  197.                     drawline  xPos,1,xPos,1+ticLen+0.02
  198.                 else
  199.                     drawline  xPos,1,xPos,1+ticLen
  200.                 endif
  201.                 drawHCenterLabel(xPos,1,labelString,0,offsety,fontName,fontSize,fontFace)
  202.             endif
  203.             i+=1
  204.         while(i<numTics)
  205.     endif
  206.     
  207.     if(which==4)        || top Axis
  208.         offsety=-ticLen-labelGrout-0.02
  209.         do
  210.             if(numType(w[i])==0)
  211.                 if(convert2Percent==0)
  212.                     labelString=num2str(w[i])
  213.                 else
  214.                     labelString=num2str(100*w[i])
  215.                 endif
  216.                 xPos=(scalePosition(w[i])-lowVal)*scaleFactor
  217.                 if(w[i]==0.5)
  218.                     drawline  xPos,0,xPos,-ticLen-0.02
  219.                 else
  220.                     drawline  xPos,0,xPos,-ticLen
  221.                 endif
  222.                 drawHCenterLabel(xPos,0,labelString,0,offsety,fontName,fontSize,fontFace)
  223.             endif
  224.             i+=1
  225.         while(i<numTics)
  226.     endif
  227.  
  228.     if(which==2)        || left axis
  229.         offsetx=-labelGrout-ticLen-0.02
  230.         offsety=0
  231.         do
  232.             if(numType(w[i])==0)
  233.                 if(convert2Percent==0)
  234.                     labelString=num2str(w[i])
  235.                 else
  236.                     labelString=num2str(100*w[i])
  237.                 endif
  238.                 xPos=1-(scalePosition(w[i])-lowVal)*scaleFactor
  239.                 if(w[i]==0.5)
  240.                     drawline  0,xPos,-ticLen-0.02,XPos
  241.                 else
  242.                     drawline  0,xPos,-ticLen,XPos
  243.                 endif
  244.                 drawVCenterLabel(0,xPos,labelString,offsetx,offsety,fontName,fontSize,fontFace,which)
  245.             endif
  246.             i+=1
  247.         while(i<numTics)
  248.     endif
  249.     
  250.     if(which==3)        || right axis
  251.         offsetx=labelGrout+ticLen+0.02
  252.         offsety=0
  253.         do
  254.             if(numType(w[i])==0)
  255.                 if(convert2Percent==0)
  256.                     labelString=num2str(w[i])
  257.                 else
  258.                     labelString=num2str(100*w[i])
  259.                 endif
  260.                 xPos=1-(scalePosition(w[i])-lowVal)*scaleFactor
  261.                 if(w[i]==0.5)
  262.                     drawline  1,xPos,1+ticLen+0.02,XPos
  263.                 else
  264.                     drawline  1,xPos,1+ticLen,XPos
  265.                 endif
  266.                 drawVCenterLabel(1,xPos,labelString,offsetx,offsety,fontName,fontSize,fontFace,which)
  267.             endif
  268.             i+=1
  269.         while(i<numTics)
  270.     endif
  271. end
  272.  
  273. |****************************************************
  274. Function/D getLowValue(waveName)
  275.     String waveName
  276.     
  277.     Wave/D     w=$waveName;
  278.     Variable     i=0,num=numpnts(w)
  279.     Variable/D    theVal
  280.     
  281.     do
  282.         theVal=scalePosition(w[i])
  283.         if(numType(theVal)==0)
  284.             return(theVal)
  285.         endif
  286.         i+=1
  287.     while(i<num)
  288.     
  289.     return(-200)                || an impossible value 
  290. end
  291.  
  292. |****************************************************
  293.  
  294. Function/d getHighValue(waveName)
  295.     String         waveName
  296.     Variable/D     theVal
  297.     
  298.     Wave/D w=$waveName;
  299.     Variable num=numpnts(w)
  300.     num-=1
  301.     do
  302.         theVal=scalePosition(w[num])
  303.         if(numType(theVal)==0)
  304.             return(theVal)
  305.         endif
  306.         num-=1
  307.     while(num>=0)
  308.     return(-20)                || an impossible value  
  309. end
  310.  
  311. |****************************************************
  312.  
  313. Function PopMenuProc_5(ctrlName,popNum,popStr) : PopupMenuControl
  314.     String ctrlName
  315.     Variable popNum
  316.     String popStr
  317.     
  318.     if(cmpstr(ctrlName,"popupSourceType")==0)
  319.         if((popNum==1) %| (popNum==3))
  320.             popupmenu popupPairedWave pos={1000,1000}
  321.         else
  322.             popupmenu popupPairedWave pos={249,24}
  323.         endif
  324.         if((popNum==4) %| (popNum==3))
  325.             Checkbox checkProbPercent pos={11,22}
  326.         else
  327.             Checkbox checkProbPercent pos={1000,1000}
  328.         endif
  329.     endif
  330.  
  331. End
  332.  
  333. Function ButtonProc_5(ctrlName) : ButtonControl
  334.     String ctrlName
  335.         
  336.     GetWindow $WinName(0,64) wsize                            || works on top Panel
  337.  
  338.     if(cmpstr(ctrlName,"bFew")==0)
  339.         Button $ctrlName, title="More Choices",rename=bMore
  340.         MoveWindow  V_left,V_top,V_right,V_bottom-120
  341.     else
  342.         Button $ctrlName, title="Fewer Choices",rename=bFew
  343.         MoveWindow  V_left,V_top,V_right,V_bottom+120
  344.     endif
  345. End
  346.  
  347. Window probAxisControl() : Panel
  348.     PauseUpdate; Silent 1        | building window...
  349.     NewPanel /W=(14,238,495,393) as "Probability Axis Control"
  350.     SetDrawLayer UserBack
  351.     DrawLine 8,44,387,44
  352.     DrawLine 8,120,387,120
  353.     DrawLine 5,156,384,156
  354.     Button button0,pos={9,129},size={90,20},proc=ButtonProc_7,title="New Graph"
  355.     CheckBox checkMirror,pos={259,49},size={100,20},title="Mirror Axis",value=0
  356.     PopupMenu popupSourceWave,pos={249,1},size={113,19},title="Source Wave:"
  357.     PopupMenu popupSourceWave,mode=2,value= #"\"(_none_;\"+WaveList(\"!tmp_qq*\",\";\",\"\")"
  358.     PopupMenu popupPairedWave,pos={1000,1000},size={111,19},title="Paired Wave:"
  359.     PopupMenu popupPairedWave,mode=5,value= #"\"(_Calculated_;\"+WaveList(\"!tmp_qq*\",\";\",\"\")"
  360.     Button button1,pos={541,133},size={150,20},proc=ButtonProc_6,title="Erase Probability Axis"
  361.     PopupMenu popupHorV,pos={9,50},size={236,19},title="Plot Probability:"
  362.     PopupMenu popupHorV,mode=1,value= #"\"Horizontal Axis;Vertical Axis\""
  363.     PopupMenu popupSourceType,pos={10,2},size={179,19},proc=PopMenuProc_5,title="Data Type:"
  364.     PopupMenu popupSourceType,mode=1,value= #"\"Raw 1 Wave;Raw 2 Waves;Processed 1 Wave;Processed 2 Waves\""
  365.     SetVariable setvarMinRange,pos={11,98},size={180,17},title="Minimum Value:"
  366.     SetVariable setvarMinRange,font="Chicago",limits={1e-10,0.9999,0.0001},value=gPAC_Min
  367.     SetVariable setvarMaxRange,pos={205,98},size={180,17},title="Maximum Value:"
  368.     SetVariable setvarMaxRange,font="Chicago",limits={0.0001,0.9999,0.001},value=gPAC_Max
  369.     Button bMore,pos={246,128},size={120,20},proc=ButtonProc_5,title="More Choices"
  370.     PopupMenu popupFont,pos={274,163},size={112,19},title="Font:"
  371.     PopupMenu popupFont,mode=4,popvalue=GetDefaultFont(""),value= #"FontList(\";\")"
  372.     PopupMenu popup1,pos={390,192},size={19,19},proc=PopMenuProc_6
  373.     PopupMenu popup1,mode=0,value= #"\"5;7;9;10;12;14;18;24;36;48;72\""
  374.     SetVariable setvarLabelGrout,pos={276,217},size={133,17},title="Label Grout:"
  375.     SetVariable setvarLabelGrout,font="Chicago"
  376.     SetVariable setvarLabelGrout,limits={0,1,0.01},value=gPAC_LabelGrout
  377.     SetVariable setvarTicLen,pos={96,182},size={130,17},title="Tick-Length"
  378.     SetVariable setvarTicLen,font="Chicago",limits={0,1,0.01},value=gPAC_TicLength
  379.     CheckBox checkFontPlain,pos={3,159},size={50,20},proc=CheckProc_1,title="Plain",value=1
  380.     CheckBox checkFontBold,pos={3,175},size={50,20},proc=CheckProc_1,title="Bold",value=0
  381.     CheckBox checkFontItalic,pos={3,191},size={60,20},proc=CheckProc_1,title="Italic",value=0
  382.     CheckBox checkFontUnderline,pos={3,207},size={90,20},proc=CheckProc_1,title="Underline",value=0
  383.     CheckBox checkFontOutline,pos={3,223},size={90,20},proc=CheckProc_1,title="Outline",value=0
  384.     CheckBox checkFontShadow,pos={3,239},size={80,20},proc=CheckProc_1,title="Shadow",value=0
  385.     SetVariable setvarFontSize,pos={276,192},size={110,17},title="Font Size:"
  386.     SetVariable setvarFontSize,font="Chicago",limits={0,INF,2},value=gPAC_FontSize
  387.     SetVariable setvarLineWidth,pos={96,161},size={160,17},title="Line Width:"
  388.     SetVariable setvarLineWidth,font="Chicago",limits={0,INF,1},value=gPAC_LineWidth
  389.     SetVariable setvarRed,pos={96,208},size={128,17},title="Red:",font="Chicago"
  390.     SetVariable setvarRed,limits={0,65535,256},value=gPAC_Red
  391.     SetVariable setvarGreen,pos={96,228},size={129,17},title="Green:",font="Chicago"
  392.     SetVariable setvarGreen,limits={0,65535,256},value=gPAC_Green
  393.     SetVariable setvarBlue,pos={97,249},size={128,17},title="Blue",font="Chicago"
  394.     SetVariable setvarBlue,limits={0,65535,256},value=gPAC_Blue
  395.     CheckBox checkProbPercent,pos={1000,1000},size={160,20},title="Probability data in %",value=0
  396.     PopupMenu popupTicSource,pos={11,73},size={186,19},proc=PopMenuProc_7,title="Tick Marks"
  397.     PopupMenu popupTicSource,mode=1,value= #"\"_Calculated_;\"+WaveList(\"!tmp_qq*\",\";\",\"\")"
  398.     CheckBox checkGrid,pos={260,71},size={50,20},title="Grid",value=1
  399.     CheckBox checkPercentLabel,pos={275,241},size={100,20},title="Label in %",value=0
  400. EndMacro
  401.  
  402. Function PopMenuProc_6(ctrlName,popNum,popStr) : PopupMenuControl
  403.     String ctrlName
  404.     Variable popNum
  405.     String popStr
  406.  
  407.     if(strlen(popstr)>0)
  408.         gPAC_FontSize=str2num(popStr)
  409.     endif
  410. End
  411.  
  412.  
  413. ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  414.  
  415. ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  416.  
  417. Function PA_setFontFace()
  418.     ControlInfo /W=probAxisControl checkFontPlain
  419.     gPAC_FontFace=0
  420.     if(V_value==1)    
  421.         CheckBox checkFontPlain value=1
  422.         CheckBox checkFontBold value=0
  423.         CheckBox checkFontItalic value=0
  424.         CheckBox checkFontUnderline value=0
  425.         CheckBox checkFontOutline value=0
  426.         CheckBox checkFontShadow value=0
  427.     else
  428.         ControlInfo /W=probAxisControl checkFontBold
  429.         if(V_value)
  430.             gPAC_FontFace+=1
  431.         endif
  432.         ControlInfo /W=probAxisControl checkFontItalic
  433.         if(V_value)
  434.             gPAC_FontFace+=2
  435.         endif
  436.         ControlInfo /W=probAxisControl checkFontUnderline
  437.         if(V_value)
  438.             gPAC_FontFace+=4
  439.         endif
  440.         ControlInfo /W=probAxisControl checkFontOutline
  441.         if(V_value)
  442.             gPAC_FontFace+=8
  443.         endif
  444.         ControlInfo /W=probAxisControl checkFontShadow
  445.         if(V_value)
  446.             gPAC_FontFace+=16
  447.         endif
  448.     endif
  449. end
  450. ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  451.  
  452. ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  453.  
  454. Function CheckProc_1(ctrlName,checked) : CheckBoxControl
  455.     String ctrlName
  456.     Variable checked
  457.     
  458.     if(cmpstr(ctrlName,"checkFontPlain")!=0)
  459.         CheckBox checkFontPlain value=0
  460.     endif
  461.     PA_setFontFace()
  462. End
  463.  
  464. ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  465.  
  466. ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  467.  
  468.  
  469. Function ButtonProc_6(ctrlName) : ButtonControl        | erase button
  470.     String ctrlName
  471.     
  472.     String topGraphWindowName=WinName(0,1)        |   find the top graph window
  473.     DoWindow /F  $topGraphWindowName                |   bring to the front
  474.     SetDrawLayer/k progAxes
  475.     DoWindow/F probAxisControl                        |  bring to front the control window
  476.     
  477. End
  478.  
  479. ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  480.  
  481. ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  482.  
  483. Function ButtonProc_7(ctrlName) : ButtonControl
  484.     String ctrlName
  485.  
  486.     probAxisMain()
  487. End
  488.  
  489. ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  490.  
  491. ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  492.  
  493. Function probAxisMain()
  494.     
  495.     || first order of business is to find out what is the input
  496.     
  497.     ControlInfo /W=probAxisControl popupSourceType
  498.     Variable         sourceType=V_value
  499.     String            SourceFileA,SourceFileB=""
  500.  
  501.     ||     SourceFileA is needed in each case 
  502.     
  503.     ControlInfo /W=probAxisControl popupSourceWave
  504.     SourceFileA=itemNumber2waveName(V_value-1)
  505.  
  506.     if((V_value==1) %| (strlen(SourceFileA)<=0))
  507.         beep
  508.         print V_value,SourceFileA
  509.         print "You must specify a source wave."
  510.         return(-1)
  511.     endif
  512.  
  513.     ControlInfo/W=probAxisControl setvarMinRange
  514.     gPAC_Min=V_value
  515.     ControlInfo/W=probAxisControl setvarMaxRange
  516.     gPAC_Max=V_value
  517.     
  518.     ControlINfo /W=probAxisControl popupHorV
  519.     Variable plotDirection=V_value
  520.     
  521.     Variable needsProcessing=0
  522.     
  523.     do
  524.         if(sourceType==1)
  525.             needsProcessing=1
  526.             break
  527.         endif
  528.         
  529.         if(sourceType==2)
  530.             ControlInfo /W=probAxisControl popupPairedWave
  531.             || we do not need to load the name "calculated" on the string
  532.             if(V_value>1)
  533.                 SourceFileB=itemNumber2waveName(V_value-1)
  534.             endif
  535.             needsProcessing=2
  536.             break
  537.         endif
  538.         
  539.         if(sourceType==3)
  540.             break
  541.         endif
  542.         
  543.         if(sourceType==4)
  544.             ControlInfo /W=probAxisControl popupPairedWave
  545.             SourceFileB=itemNumber2waveName(V_value-1)
  546.             break
  547.         endif
  548.     while(0)
  549.     
  550.     
  551.     || pre-process the data if necessary
  552.         
  553.     if(needsProcessing>0)
  554.         String processedName="processed_"
  555.         probAxisProcess(needsProcessing,SourceFileA,SourceFileB,processedName)
  556.     endif
  557.         
  558.     || at this point we have 2 or 3 waves, from which we plot two depending
  559.     || on the Horizontal or vertical choice
  560.     || plotDirection=1 for horizontal, 2 for vertical
  561.     
  562.     do
  563.         if(needsProcessing==0)
  564.             ControlInfo /W=probAxisControl checkProbPercent
  565.             if(V_value==1)    || if data is in % divide by 100
  566.                 String              newSourceFile="Source_100"
  567.                 Duplicate/O     $SourceFileA,$newSourceFile
  568.                 Wave             w=$newSourceFile
  569.                 w=w/100
  570.                 plotProbabilityWaves(newSourceFile,SourceFileB,plotDirection)            
  571.             else
  572.                 plotProbabilityWaves(SourceFileA,SourceFileB,plotDirection)
  573.             endif
  574.             break
  575.         endif
  576.     
  577.         if(needsProcessing==1)
  578.             plotProbabilityWaves(processedName,SourceFileA,plotDirection)
  579.             break
  580.         endif
  581.         
  582.         if(needsProcessing==2)
  583.             plotProbabilityWaves(processedName,SourceFileB,plotDirection)
  584.             break
  585.         endif
  586.     while(0)
  587.     
  588.     cleanup()
  589. end
  590.  
  591. ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  592.  
  593. ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  594.  
  595. function cleanup()
  596.     KillWaves/z $"tmp_qq_ticWave"
  597. end
  598.  
  599. ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  600. |    
  601. |    plotProbabilityWaves:    we assume that waveA contains the range [0,1)
  602. |                            and that waveB contains some arb values.
  603. |                            We scale waveA using the probability scale and
  604. |                            plot the resultant against waveB depending on the 
  605. |                            specified direction
  606. |
  607. ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  608.  
  609. Function plotProbabilityWaves(waveA,waveB,plotDirection)
  610.     String         waveA,waveB
  611.     Variable     plotDirection
  612.  
  613.     Wave/D         tmp_qq_a=$waveA
  614.     Wave/D            tmp_qq_b=$waveB
  615.     String            dupWaveName=waveA+"_d"
  616.     
  617.     SetDrawEnv     gstart                    |    start grouping here
  618.  
  619.     Variable         index=0
  620.     do
  621.         sprintf  dupWaveName "%s_d%d",waveA,index
  622.         index+=1
  623.     while(exists(dupWaveName)!=0)
  624.     
  625.     Duplicate/O      tmp_qq_a,$dupWaveName
  626.     Wave/D            tmp_qq_aDup=$dupWaveName
  627.         
  628.     tmp_qq_aDup=scalePosition(tmp_qq_aDup)
  629.     
  630.     Variable/D  z,n,normalization
  631.         
  632.     ControlInfo/W=probAxisControl setvarTicLen
  633.     gPAC_TicLength=V_value
  634.     ControlInfo/W=probAxisControl setvarFontSize
  635.     gPAC_FontSize=V_value
  636.     ControlInfo/W=probAxisControl setvarLabelGrout
  637.     gPAC_LabelGrout=V_value
  638.  
  639.     ControlInfo /W=probAxisControl popupFont
  640.     String fontName= S_value
  641.     
  642.     
  643.     ControlInfo/W=probAxisControl checkMirror
  644.     Variable mirror=V_value
  645.     ControlInfo/W=probAxisControl checkGrid
  646.     Variable isGrid=V_value
  647.     
  648.     String TicWaveName=""
  649.     ControlInfo/W=probAxisControl popupTicSource
  650.     
  651.     if(V_value>1)
  652.         TicWaveName=tickWave2MinMax(V_value)
  653.     endif
  654.     
  655.     if(gPAC_Min>=gPAC_Max)
  656.         Abort "limits must be Low->High"
  657.         SetDrawEnv gstop            |     end grouping
  658.         return(-1)
  659.     endif
  660.     
  661.     z=scalePosition(gPAC_Min)
  662.     n=scalePosition(gPAC_Max)
  663.     
  664.     normalization=1/(n-z)
  665.     tmp_qq_aDup=(tmp_qq_aDup-z)*normalization
  666.  
  667.     || Duplicate/o tmp_qq_aDup,$"NewDup"
  668.     || Edit $"NewDup"
  669.     
  670.     if(strlen(TicWaveName)<=0)
  671.         TicWaveName=setDefProbTics()
  672.     endif
  673.     
  674.     if(plotDirection==1)
  675.         if(strlen(waveB)<=0)                            || there is no wave name to plot against
  676.             String          localName="tmp_qq_run"
  677.             Variable     num=numpnts(tmp_qq_aDup)
  678.             make/D/O/N=(num) $localName=x
  679.             Wave/D     tmp_qq_c=$localName
  680.             SetScale/I     x,0,num,tmp_qq_c
  681.             Display     tmp_qq_c vs tmp_qq_aDup    
  682.         else
  683.             Display tmp_qq_b vs tmp_qq_aDup    
  684.         endif
  685.         
  686.         SetAxis bottom 0,1
  687.         
  688.         drawProbabilityAxis(1,TicWaveName,fontName,gPAC_FontSize,gPAC_FontFace,gPAC_TicLength,gPAC_LabelGrout)
  689.         if(mirror)
  690.             ModifyGraph margin(top)=70
  691.             drawProbabilityAxis(4,TicWaveName,fontName,gPAC_FontSize,gPAC_FontFace,gPAC_TicLength,gPAC_LabelGrout)
  692.         endif
  693.         if(isGrid)
  694.             drawProbGrid(1,TicWaveName)
  695.             ModifyGraph grid(left)=1
  696.         endif
  697.     else
  698.         if(strlen(waveB)>0)                            || there exists a wave name to plot against
  699.             Display  tmp_qq_aDup vs tmp_qq_b        
  700.         else
  701.             Display tmp_qq_aDup
  702.         endif
  703.         
  704.         SetAxis left 0,1
  705.         drawProbabilityAxis(2,TicWaveName,fontName,gPAC_FontSize,gPAC_FontFace,gPAC_TicLength,gPAC_LabelGrout)
  706.         if(mirror)
  707.             ModifyGraph margin(right)=70
  708.             drawProbabilityAxis(3,TicWaveName,fontName,gPAC_FontSize,gPAC_FontFace,gPAC_TicLength,gPAC_LabelGrout)
  709.         endif
  710.         if(isGrid)
  711.             drawProbGrid(2,TicWaveName)
  712.             ModifyGraph grid(bottom)=1
  713.         endif
  714.     endif    
  715.     ModifyGraph mode=3,marker=41
  716.     SetDrawEnv gstop            |     end grouping
  717. end
  718.  
  719. ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  720.  
  721. ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  722.  
  723. Function/S  itemNumber2waveName(item)
  724.     Variable item
  725.     
  726.     String local=GetStrFromList(WaveList("!tmp_qq*",";" , ""), item-1, ";")
  727.     
  728.     return (GetStrFromList(WaveList("!tmp_qq*",";" , ""), item-1, ";"))
  729. end
  730.  
  731. ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  732. |
  733. |    probAxisProcess:    Requires input for the needsProcessing flag and 3 names.
  734. |                        
  735. ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  736.  
  737. Function probAxisProcess(needsProcessing,SourceFileA,SourceFileB,processedName)
  738.     Variable     needsProcessing
  739.     String        SourceFileA,SourceFileB,processedName
  740.     
  741.     Wave/D        w1=$SourceFileA
  742.     Wave/D        tmp_qq_b=$SourceFileB
  743.         
  744.         
  745.     Sort w1,w1                                    
  746.     Variable numPoints=numpnts(w1)
  747.     Make/D/O/N=(numPoints)    $processedName
  748.     Wave/D            w3=$processedName            || must follow the duplicate
  749.     SetScale /I x,1,numPoints,w3
  750.     w3=x                                            || set to the initial population number
  751.         
  752.     Duplicate/O     w1,$"tmp_qqDup"
  753.     Wave/D            tmp_qq_a2=$"tmp_qqDup"
  754.     
  755.     if(needsProcessing==1)
  756.         Sort tmp_qq_a2,tmp_qq_a2                    || sorting the duplicated not original        
  757.     else
  758.         Sort tmp_qq_a2,tmp_qq_a2    ,tmp_qq_b        || reorder the second wave if necessary;    
  759.     endif
  760.     
  761.     Variable i=1
  762.     Variable j
  763.     || Handle the case of equal values
  764.         
  765.     do
  766.         if(tmp_qq_a2[i]==tmp_qq_a2[i-1])
  767.             j=i
  768.             do
  769.                 w3[j]-=1
  770.                 j+=1
  771.             while((j<numPoints) %& (tmp_qq_a2[j]==tmp_qq_a2[j-1]))
  772.             i=j
  773.         endif
  774.         i+=1
  775.     while(i<numPoints)    
  776.     
  777.     || Find the Fraction of the population below each value
  778.     || qqq  Comment the following line for dividing by the total number of points
  779.     numPoints+=1
  780.     w3=w3/numPoints
  781.  
  782.     KillWaves/z    tmp_qq_a2                            || cleanup
  783. end
  784.  
  785. ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  786.  
  787. ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  788.  
  789. Function drawProbGrid(which,TicWaveName)
  790.     Variable     which
  791.     String         TicWaveName
  792.     
  793.     Variable/D         i=0,xp,first=0
  794.     Wave/D            w=$TicWaveName
  795.     Variable        num=numpnts(w)
  796.     
  797.     Variable/D    lowVal=getLowValue(TicWaveName)
  798.     Variable/D    highVal=getHighValue(TicWaveName)
  799.     
  800.     if((lowVal<-50) %| (highVal<-50))
  801.         Print "Processed wave contains bad values."
  802.         Print lowVal,highVal
  803.         return(0)
  804.     endif
  805.         
  806.     Variable/D    scaleFactor=1.0/(highVal-lowVal)    
  807.  
  808.     Variable     last=num
  809.     Variable    sub
  810.         
  811.     do
  812.         if(numType(w[num-1])==0)
  813.             last=num-2
  814.             break
  815.         endif
  816.         num-=1
  817.     while(num>2)
  818.     
  819.     || the following loop does not draw a grid line at the first and
  820.     || the last points
  821.     
  822.     do
  823.         if(numType(w[first])==0)
  824.             i=first+1
  825.             break
  826.         endif
  827.         first+=1
  828.     while(first<last)
  829.             
  830.     if(which==1)                            || vertical grid
  831.         do
  832.             xp=(scalePosition(w[i])-lowVal)*scaleFactor
  833.             if(numType(xp)==0)
  834.                 SetDrawEnv linefgc=(0x6000,0x6000,0xffff)
  835.                 SetDrawEnv dash= 1
  836.                 drawline xp,0,xp,1
  837.             endif
  838.             i+=1
  839.         while(i<=last)
  840.     else                                        || Horizontal grid
  841.         do
  842.             xp=(scalePosition(w[i])-lowVal)*scaleFactor
  843.             if(numType(xp)==0)
  844.                 SetDrawEnv linefgc=(0x6000,0x6000,0xffff)
  845.                 SetDrawEnv dash= 1
  846.                 drawline 0,xp,1,xp
  847.             endif
  848.             i+=1
  849.         while(i<=last)
  850.     endif
  851. end
  852.  
  853. ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  854.  
  855. ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  856.  
  857. function drawHCenterLabel(x1,y1,labelString,offsetx,offsety,fontName,fontSize,fontFace)
  858.     String         fontName
  859.     Variable     fontSize
  860.     Variable     fontFace
  861.     Variable     x1,y1,offsetx,offsety
  862.     String        labelString
  863.     
  864.     | Note, the following needs to be converted into a string and then executed
  865.     
  866.     execute "SetDrawEnv fname= \""+fontName +"\""
  867.     SetDrawEnv     fsize=fontSize
  868.     SetDrawEnv     fstyle=fontFace
  869.  
  870.     SetDrawEnv textxjust=1
  871.     DrawText x1+offsetx,y1+offsety,labelString
  872. end
  873.  
  874. ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  875. |
  876. | primitive that draws a centered label for left or right axis
  877. | x and y offsets are in plot relative fractions
  878. |
  879. ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  880.  
  881.  
  882. function drawVCenterLabel(x1,y1,labelString,offsetx,offsety,fontName,fontSize,fontFace,which)
  883.     String         fontName
  884.     Variable     fontSize
  885.     Variable     fontFace
  886.     Variable    which
  887.     Variable     x1,y1,offsetx,offsety
  888.     String        labelString
  889.     
  890.     | Note, the following needs to be converted into a string and then executed
  891.     
  892.     execute("SetDrawEnv     fname=\""+fontName+"\"");
  893.     SetDrawEnv     fsize=fontSize
  894.     SetDrawEnv     fstyle=fontFace
  895.  
  896.     if(which==3)                        | right axis we want left justified labels
  897.         SetDrawEnv textxjust=0
  898.     else if(which==2)                        | left axis has 
  899.             SetDrawEnv textxjust=2
  900.     endif
  901.     
  902.     SetDrawEnv textyjust=1
  903.     DrawText x1+offsetx,y1+offsety,labelString
  904. end
  905.  
  906. ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  907.  
  908. Function PopMenuProc_7(ctrlName,popNum,popStr) : PopupMenuControl
  909.     String ctrlName
  910.     Variable popNum
  911.     String popStr
  912.  
  913.     if(popNum>1)
  914.         SetVariable setVarMinRange pos={1000,1000}
  915.         SetVariable setVarMaxRange pos={1000,1000}
  916.         tickWave2MinMax(popNum)
  917.     else
  918.         SetVariable setVarMinRange pos={11,98}
  919.         SetVariable setVarMaxRange pos={205,98}
  920.         ControlInfo/W=probAxisControl setvarMinRange
  921.         gPAC_Min=V_value
  922.         ControlInfo/W=probAxisControl setvarMaxRange
  923.         gPAC_Max=V_value
  924.     endif
  925. End
  926.  
  927.  
  928. ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  929.     || in the following we set up a local tick mark wave for the case that the user
  930.     || specifies only external limits.  We use a fixed wave for standard interval and
  931.     || verify that all points  in the wave fall between the min and max limits
  932. ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  933.  
  934. Function/S setDefProbTics()
  935.     
  936.     String waveName
  937.  
  938.         waveName="tmp_qq_ticWave"
  939.         Make/D/O      $waveName={NaN,Nan,0.01,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,0.99,NaN,Nan}
  940.         Wave/D        ww=$waveName
  941.         
  942.         ControlInfo/W=probAxisControl setvarMinRange
  943.         gPAC_Min=V_value
  944.         ControlInfo/W=probAxisControl setvarMaxRange
  945.         gPAC_Max=V_value
  946.     
  947.         if(gPAC_Min<0.01)
  948.             if(gPAC_Min<0.001)
  949.                 ww[0]=gPAC_Min
  950.                 ww[1]=0.001
  951.             else
  952.                 ww[1]=gPAC_Min
  953.             endif
  954.             
  955.         endif
  956.         
  957.         variable num=numpnts(ww)
  958.         if(gPAC_Max>0.99)
  959.             if(gPAC_Max>0.999)
  960.                 ww[num-2]=0.999
  961.                 ww[num-1]=gPAC_Max
  962.             else
  963.                 ww[num-2]=gPAC_Max
  964.             endif
  965.         endif
  966.         
  967.         variable i=0
  968.         variable/D  zz
  969.         do
  970.             zz=ww[i]
  971.             if((ww[i]<gPAC_Min) %| (ww[i]>gPAC_Max))
  972.                 ww[i]=NaN
  973.             endif
  974.             i+=1
  975.         while(i<num)
  976.         
  977.     return(waveName)
  978. end
  979.  
  980.  
  981.  
  982. Function/S tickWave2MinMax(pop_value)
  983.     Variable pop_value
  984.     
  985.     String     TicWaveName=""
  986.     TicWaveName=itemNumber2waveName(pop_value-1)
  987.     || set the min and max if the user specifies a wave of tickmarks
  988.     if(strlen(TicWaveName)>0)    
  989.         Wave/D  whatever=$TicWaveName
  990.         Sort whatever,whatever                        || qq sort 1
  991.         gPAC_Min=whatever[0]
  992.         gPAC_Max=whatever[numpnts(whatever)-1]
  993.     endif
  994.     
  995.     return(TicWaveName)
  996. End